package io.renren.dao;

import io.renren.common.dao.BaseDao;
import io.renren.dto.FoodDTO;
import io.renren.dto.FoodmxDTO;
import io.renren.entity.FoodmxEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 辅材库明细表
 *
 * @author 罗胜平 781757616@qq.com
 * @since 1.0.0 2019-11-22
 */
@Mapper
public interface FoodmxDao extends BaseDao<FoodmxEntity> {
    @Select(" select * from canteens_foodmx   where " +
            " DATE_FORMAT('${time}','%Y-%m-%d') = DATE_FORMAT(operator_time,'%Y-%m-%d')  GROUP BY batch_number"
            )
    List<FoodmxDTO> selectFoodmx(String time);
    @Select(" select fd.food_name,fd.unit,SUM(mx.food_num)As  totaoNum, mx.* from canteens_foodmx mx,canteens_food fd where mx.food_id =fd.food_id  " +
            "and mx.canteen_id = '${canteenId}' "+"${variety} "+ "${foodname} "+" GROUP BY food_id ")
    List<FoodmxDTO> selectAllFoodmx(String foodname,String variety, Long canteenId);
    @Select(" select * FROM canteens_foodmx where food_id =  '${foodId}' ")
    List<FoodmxDTO> selectFoodIdmx(Long foodId);
    @Select(" DELETE FROM canteens_foodmx where foodmx_id =  '${order}' ")
     void delectFoodIdmx(Long order);

    @Select("select B.purchase_num as  food_num from canteens_temporary_order A ,canteens_temporary_ordermx B " +
            " where A.temporary_id = B.temporary_id  and food_id ='${foodId}' " +
            " and  A.sign = '${sign}' and A.canteen_id = '${canteenId}'  ")
    FoodmxDTO getTemCollFood(Long foodId, int sign, Long chedId, Long canteenId);
    @Select(" select sum(food_num) totaoNumber FROM canteens_foodmx where food_id=  '${foodId}'  and canteen_id ='${canteenId}' GROUP BY food_id")
    FoodmxDTO getTotaoNum(Long foodId, Long canteenId);
}